package com.cleaningcloud.cld.service.impl;

import java.util.List;

import com.cleaningcloud.cld.domain.CldAssetsRecord;
import com.cleaningcloud.cld.mapper.CldAssetsRecordMapper;
import com.cleaningcloud.cld.mapper.PublicCommonMapper;
import com.cleaningcloud.common.core.utils.DateUtils;
import com.cleaningcloud.common.security.utils.SecurityUtils;
import net.sourceforge.pinyin4j.PinyinHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cleaningcloud.cld.mapper.CldAssetsMapper;
import com.cleaningcloud.cld.domain.CldAssets;
import com.cleaningcloud.cld.service.ICldAssetsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 资产信息Service业务层处理
 * 
 * @author cleaningcloud
 * @date 2024-10-06
 */
@Service
public class CldAssetsServiceImpl implements ICldAssetsService 
{
    @Autowired
    private CldAssetsMapper cldAssetsMapper;

    @Autowired
    private CldAssetsRecordMapper assetsRecordMapper;


    /**
     * 查询资产信息
     * 
     * @param assetsId 资产信息主键
     * @return 资产信息
     */
    @Override
    public CldAssets selectCldAssetsByAssetsId(Long assetsId)
    {
        return cldAssetsMapper.selectCldAssetsByAssetsId(assetsId);
    }

    @Override
    public List<CldAssets> getList() {
        return cldAssetsMapper.getList();
    }

    /**
     * 查询资产信息列表
     * 
     * @param cldAssets 资产信息
     * @return 资产信息
     */
    @Override
    public List<CldAssets> selectCldAssetsList(CldAssets cldAssets)
    {
        return cldAssetsMapper.selectCldAssetsList(cldAssets);
    }

    /**
     * 新增资产信息
     * 
     * @param cldAssets 资产信息
     * @return 结果
     */
    @Override
    public int insertCldAssets(CldAssets cldAssets)
    {
        cldAssets.setCreateTime(DateUtils.getNowDate());
        cldAssets.setUpdateTime(cldAssets.getCreateTime());
        cldAssets.setCreateId(SecurityUtils.getUserId());
        cldAssets.setCreateName(SecurityUtils.getUsername());
        cldAssets.setFlag(0L);
        cldAssets.setAssetsNo(convertChineseToPinyin(cldAssets.getAssetsName()));
        return cldAssetsMapper.insertCldAssets(cldAssets);
    }

    /**
     * 将中文转换为拼音并获取首字母
     *
     * @param chinese 中文字符串
     * @return 拼音字符串
     */
    public static String convertChineseToPinyin(String chinese) {
        StringBuilder pinyin = new StringBuilder();
        for (char c : chinese.toCharArray()) {
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
            if (pinyinArray != null && pinyinArray.length > 0) {
                pinyin.append(pinyinArray[0].charAt(0));
            } else {
                pinyin.append(c);
            }
        }
        return pinyin.toString().toUpperCase();
    }

    /**
     * 修改资产信息
     * 
     * @param cldAssets 资产信息
     * @return 结果
     */
    @Override
    public int updateCldAssets(CldAssets cldAssets)
    {
        return cldAssetsMapper.updateCldAssets(cldAssets);
    }

    /**
     * 批量删除资产信息
     * 
     * @param assetsIds 需要删除的资产信息主键
     * @return 结果
     */
    @Override
    public int deleteCldAssetsByAssetsIds(Long[] assetsIds)
    {
        return cldAssetsMapper.deleteCldAssetsByAssetsIds(assetsIds);
    }

    /**
     * 删除资产信息信息
     * 
     * @param assetsId 资产信息主键
     * @return 结果
     */
    @Override
    public int deleteCldAssetsByAssetsId(Long assetsId)
    {
        return cldAssetsMapper.deleteCldAssetsByAssetsId(assetsId);
    }
}
